#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteDuplicates(struct ListNode* head) {
    if (head == NULL || head->next == NULL)
        return head;
    int a[201] = { 0 };
    struct ListNode* ptail = head;
    while (ptail)
    {
        a[ptail->val + 100]++;
        ptail = ptail->next;
    }
    ptail = head;
    while (ptail && ptail->next)
    {
        if (a[ptail->next->val + 100] == 1)
        {
            ptail = ptail->next;
            a[ptail->val + 100] = 1;
        }
        else
        {
            struct ListNode* f = ptail->next;
            ptail->next = f->next;
            free(f);
        }
    }
    if (a[head->val + 100] > 1)
        return head->next;
    return head;
}